package com.xingdata.jjxc.activity;

import java.util.HashMap;

import com.xingdata.jjxc.App;
import com.xingdata.jjxc.Common;
import com.xingdata.jjxc.R;
import com.xingdata.jjxc.R.id;
import com.xingdata.jjxc.R.layout;
import com.xingdata.jjxc.base.Base1Activity;
import com.xingdata.jjxc.enty.RespEntity;
import com.xingdata.jjxc.http.HttpResponseListener;
import com.xingdata.jjxc.http.HttpUtil;
import com.xingdata.jjxc.utils.Log;
import com.xingdata.jjxc.utils.SharedPreTools;
import com.xingdata.jjxc.utils.StringUtil;
import com.xingdata.jjxc.utils.SystemInfo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

// 发布信息

public class IssueActivity extends Base1Activity implements OnClickListener {
	private TextView address;
	private String TAG = "IssueActivity";
	private EditText title, body;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.appeal_button:

			if (!StringUtil.isStringNull(title.getText().toString().trim())) {
				showToast("标题为空");
				return;
			}
			
			if (!StringUtil.isStringNull(body.getText().toString().trim())) {
				showToast("内容为空");
				return;
			}
			
			
			

			addDiscover();
			break;

		}
	}

	@Override
	protected int getContentViewId() {
		// TODO Auto-generated method stub
		return R.layout.activity_issue;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "发布消息";
	}

	@Override
	protected void initViews() {
		((ImageView) findViewById(R.id.title_back)).setOnClickListener(this);
		address = (TextView) findViewById(R.id.appeal_address);
		address.setText(SharedPreTools.getString(this, Common.LOACTION, "未知"));
		title = (EditText) findViewById(R.id.appeal_title);
		title.setSelection(title.getText().toString().length());
		body = (EditText) findViewById(R.id.appeal_body);
		findViewById(R.id.appeal_button).setOnClickListener(this);
	}

	/**
	 * 上传成功后 提交到后台
	 * 
	 * @param uploadFileKey
	 * 
	 * @param key
	 *            文件名称
	 */
	private void addDiscover() {
		paramsMap = new HashMap<String, String>();
		paramsMap.put("userid", SystemInfo.getUserInfo().getUserid());
		paramsMap.put("access_token", SystemInfo.getTokenEntity().getToken()); // 验证码
		paramsMap.put("dis_type", "2");// 发现类型
		// 发现类型【1精彩2求助】（必）选1时，只需传dis_videourl（必）选2时，只需传dis_content（必）
		paramsMap.put("dis_title", title.getText().toString().trim());// 发现标题
		paramsMap.put("dis_content", body.getText().toString().trim());// 发现内容
		// paramsMap.put(
		// "dis_imageurl",
		// pathHead + pathName_img + App.DOMAINNAME_QINIU
		// + uploadFileKey.replaceAll(".mp4", ".png"));// 封面URL
		// http://img.irishud.com.cn/dist_20150917_004030.mp4_thumbail
		// paramsMap.put("dis_videourl", pathHead + pathName_video
		// + App.DOMAINNAME_QINIU + uploadFileKey );// 视频url
		paramsMap
				.put("dis_lng", SharedPreTools.getString(this, Common.LNG, ""));// 当前经度
		paramsMap
				.put("dis_lat", SharedPreTools.getString(this, Common.LAT, ""));// 当前纬度
		paramsMap.put("dis_address",
				SharedPreTools.getString(this, Common.LOACTION, "未知"));// 定位地址
		paramsMap.put("address_flag", "0");// 定位是否打开
		HttpUtil.getInstance(this).Post(App.ZZD_REQUEST_ADDDISCOVER, paramsMap,
				new HttpResponseListener() {

					@Override
					public void onSuccess(RespEntity respEntity) {
						Log.i(TAG, "后台提交成功");
						dismissProgressDialog();
						showToast("求助发布成功");
						finish();
					}

					@Override
					public void onLoading(int vurrent) {

					}

					@Override
					public void onFailure(String result) {
						// TODO Auto-generated method stub

					}
				});
	}
}
